package com.xiaochong.tir.trades.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Created by org on 2018/6/15.
 * 币安队列绑定
 */
@Configuration
@Component
public class BinanceQueenConfig {
    /**
     * 配置消息交换机
     * 针对消费者配置
     FanoutExchange: 将消息分发到所有的绑定队列，无routingkey的概念
     HeadersExchange ：通过添加属性key-value匹配
     DirectExchange:按照routingkey分发到指定队列
     TopicExchange:多关键字匹配
     */
    @Bean
    public DirectExchange BinanceNodeAPIExchange() {
        return new DirectExchange(ExchangeQueue.Exchange.EX_NODE_API_MQ, true, false);
    }
    @Bean
    public Queue queueTradesBinanceBtcAction(){
        return new Queue(BinanceMqQueue.QUEUE_TRADES_BINANCE_BTC, true);
    }
    @Bean
    public Binding bindingTradesBinanceBtcAction(){
        return BindingBuilder.bind(queueTradesBinanceBtcAction()).to(BinanceNodeAPIExchange()).with(BinanceMqQueue.QUEUE_TRADES_BINANCE_BTC);
    }

    @Bean
    public Queue queueTradesBinanceEthAction(){
        return new Queue(BinanceMqQueue.QUEUE_TRADES_BINANCE_ETH, true);
    }
    @Bean
    public Binding bindingTradesBinanceEthAction(){
        return BindingBuilder.bind(queueTradesBinanceEthAction()).to(BinanceNodeAPIExchange()).with(BinanceMqQueue.QUEUE_TRADES_BINANCE_ETH);
    }

    @Bean
    public Queue queueTradesBinanceUsdtAction(){
        return new Queue(BinanceMqQueue.QUEUE_TRADES_BINANCE_USDT, true);
    }
    @Bean
    public Binding bindingTradesBinanceUsdtAction(){
        return BindingBuilder.bind(queueTradesBinanceUsdtAction()).to(BinanceNodeAPIExchange()).with(BinanceMqQueue.QUEUE_TRADES_BINANCE_USDT);
    }

    @Bean
    public Queue queueTradesBinanceBnbAction(){
        return new Queue(BinanceMqQueue.QUEUE_TRADES_BINANCE_BNB, true);
    }
    @Bean
    public Binding bindingTradesBinanceBnbAction(){
        return BindingBuilder.bind(queueTradesBinanceBnbAction()).to(BinanceNodeAPIExchange()).with(BinanceMqQueue.QUEUE_TRADES_BINANCE_BNB);
    }
}
